package com.lfg.leetcode.leetcode100;

import java.util.ArrayList;
import java.util.List;

public class No118generate {

    public static void main(String[] args) {
        System.out.println("[" + generate(5) + "]");
    }


    public static List<List<Integer>> generate(int numRows) {
        List<List<Integer>> ret = new ArrayList<>(numRows);
        ArrayList<Integer> list = new ArrayList<>(1);
        list.add(1);
        ret.add(list);
        for (int i = 1; i < numRows; i++) {
            List<Integer> data = ret.get(ret.size() - 1);
            List<Integer> l = new ArrayList<>(data.size() + 1);
            for (int j = 0; j <= i; j++) {
                int num = 0;
                int left = j - 1;
                int right = j ;
                if (left >= 0) {
                    num = data.get(left);
                }
                if (right < data.size()) {
                    num += data.get(right);
                }
                l.add(num);
            }
            ret.add(l);
        }
        return ret;
    }
}
